Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new function of SpansReg #367

Merged
merged 3 commits into from
Oct 27, 2024
Merged

added new function of SpansReg #367

merged 3 commits into from
Oct 27, 2024

Conversation

shewer
Copy link
Contributor

@shewer shewer commented Sep 23, 2024

擴展 Spans

-- return Spans 
cand:spans()
segment:spans()
composition:spans()

-- spans api 
spans:add_vertex( size_t vertex)  
spans:clear() --  vertices = {}
spans.vertices -- return **size_t** of  lua_table
spans.vertices = { 5, 4, 2 , "3 " ,4 }  -- vertices = { 2, 3, 4, 5}

@hchunhui
Copy link
Owner

@ksqsf 可以请你帮忙review一下吗?

Copy link
Contributor

@ksqsf ksqsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lua 部分不太熟跳过了,其余部分 LGTM。

Comment on lines +2058 to +2073
int raw_set_vertices(lua_State *L) {
C_State C;
auto &spans = LuaType<Spans &>::todata(L, 1);
if (lua_istable(L, 2)) {
spans.Clear();
for (auto vertex : LuaType<vector<int>>::todata(L, 2, &C)) {
if (vertex >=0) {
spans.AddVertex(vertex);
}
}
}
else {
luaL_error(L, "bad argument #2 to set_vertices (table expected, got %s)" , lua_typename(L, 2));
}
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我对 Lua API 不熟,这部分 skip 了。

src/types.cc Outdated Show resolved Hide resolved
Comment on lines +111 to +119
inline Spans spans(const T &seg) {
Spans res;
if (auto phrase = As<Phrase>(
Candidate::GetGenuineCandidate(seg.GetSelectedCandidate()))) {
res.AddSpans(phrase->spans());
}
res.AddSpan(seg.start, seg.end);
return res;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hchunhui hchunhui merged commit 1bde771 into hchunhui:master Oct 27, 2024
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants